package com.study.jyg.rxjava2study.finaly;

public class FinalString {
    public static final String RXJAVA_BASE = "一.基本创建\n" +
            "需求场景: 完整的创建被观察者对象\n" +
            "\n" +
            "1. create（）\n" +
            "你可以使用Create操作符创建一个完整的Observable，可以传递onNext，onError和onCompleted等事件。\n" +
            "\n" +
            "代码示例：\n" +
            "\n" +
            " Observable.create(new ObservableOnSubscribe<Integer>() {\n" +
            "            @Override\n" +
            "            public void subscribe(ObservableEmitter<Integer> e) throws Exception {\n" +
            "                e.onNext(1);\n" +
            "                e.onNext(2);\n" +
            "                e.onNext(3);\n" +
            "            }\n" +
            "        }).subscribe(new Observer<Integer>() {\n" +
            "            @Override\n" +
            "            public void onSubscribe(Disposable d) {\n" +
            "                Log.d(TAG, \"onSubscribe: \");\n" +
            "            }\n" +
            "\n" +
            "            @Override\n" +
            "            public void onNext(Integer integer) {\n" +
            "                Log.d(TAG, \"onNext: \"+integer);\n" +
            "            }\n" +
            "\n" +
            "            @Override\n" +
            "            public void onError(Throwable e) {\n" +
            "                Log.d(TAG, \"onError: \"+e);\n" +
            "            }\n" +
            "\n" +
            "            @Override\n" +
            "            public void onComplete() {\n" +
            "                Log.d(TAG, \"onComplete: \");\n" +
            "            }\n" +
            "        });\n"+
            "\n"+
            "\n"+
            "注意:当观察者发送一个Complete/Error事件后，被观察者在，Complrte/Error事件将会继续发送，但观察者收到Complete/Error事件后，不会继续接收任何事件。被观察者可以不发生Complete/Erroe事件";


    public static final String RXJAVA_FASTCREATE = "二.快速创建\n" +
            "需求场景：快速的创建被观察者对象\n" +
            "\n" +
            "1.just()\n" +
            "作用:快速创建1个被观察者对象（Observable）\n" +
            "发送事件的特点：直接发送传入的事件\n" +
            "注意1:just最多只能发送9个参数\n" +
            "注意2：如果你传递null给Just，它会返回一个发射null值的Observable\n" +
            "\n" +
            "代码示例\n" +
            "  Observable.just(1, 2, 3)\n" +
            "               .subscribe(new Observer<Integer>() {\n" +
            "                   @Override\n" +
            "                   public void onSubscribe(Disposable d) {\n" +
            "                       Log.d(TAG, \"onSubscribe: \"+d);\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onNext(Integer integer) {\n" +
            "                       Log.d(TAG, \"onNext: \"+integer);\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onError(Throwable e) {\n" +
            "                       Log.d(TAG, \"onError: \");\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onComplete() {\n" +
            "                       Log.d(TAG, \"onComplete: \");\n" +
            "                   }\n" +
            "               });\n" +
            "\n" +
            "\n" +
            "2.fromArray（）\n" +
            "作用：快速创建一个被观察者对象\n" +
            "发送事件的特点：直接发送传入的数据数组\n" +
            "fromArray会将数组中的数据转换为Observable对象\n" +
            "应用场景:被观察者对象（Observable） & 发送10个以上事件（数组形式),数组遍历\n" +
            "图中的From包括fromArray（）以及下面的fromIterable（）\n" +
            "\n" +
            "\n" +
            "Integer[] items = { 0, 1, 2, 3, 4 };\n" +
            "        Observable.fromArray(items)\n" +
            "               .subscribe(new Observer<Integer>() {\n" +
            "                   @Override\n" +
            "                   public void onSubscribe(Disposable d) {\n" +
            "                       Log.d(TAG, \"onSubscribe: \"+d);\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onNext(Integer integer) {\n" +
            "                       Log.d(TAG, \"onNext: \"+integer);\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onError(Throwable e) {\n" +
            "                       Log.d(TAG, \"onError: \");\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onComplete() {\n" +
            "                       Log.d(TAG, \"onComplete: \");\n" +
            "                   }\n" +
            "               });\n" +
            "\n" +
            "\n" +
            "3.fromIterable（）\n" +
            "作用:快速创建1个被观察者对象（Observable）\n" +
            "发送事件的特点:直接发送 传入的集合List数据\n" +
            "应用场景:1.快速创建 被观察者对象（Observable） & 发送10个以上事件（集合形式）2.集合元素遍历\n" +
            "  List<Integer> list = new ArrayList<>();\n" +
            "        list.add(1);\n" +
            "        list.add(2);\n" +
            "        list.add(3);\n" +
            "        Observable.fromIterable(list)\n" +
            "               .subscribe(new Observer<Integer>() {\n" +
            "                   @Override\n" +
            "                   public void onSubscribe(Disposable d) {\n" +
            "                       Log.d(TAG, \"onSubscribe: \"+d);\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onNext(Integer integer) {\n" +
            "                       Log.d(TAG, \"onNext: \"+integer);\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onError(Throwable e) {\n" +
            "                       Log.d(TAG, \"onError: \");\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onComplete() {\n" +
            "                       Log.d(TAG, \"onComplete: \");\n" +
            "                   }\n" +
            "               });\n" +
            "    }\n" +
            "\n" +
            "\n" +
            "4.其他\n" +
            "下列方法一般用于测试使用\n" +
            "empty():仅发送Complete事件，直接通知完成\n" +
            "error():仅发送Error事件，直接通知异常\n" +
            "never():不发送任何事件\n" +
            "\n" +
            "\n" +
            " Observable.empty()\n" +
            "               .subscribe(new Observer<Object>() {\n" +
            "                   @Override\n" +
            "                   public void onSubscribe(Disposable d) {\n" +
            "                       Log.d(TAG, \"onSubscribe: \"+d);\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onNext(Object o) {\n" +
            "                       Log.d(TAG, \"onNext: \"+o);\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onError(Throwable e) {\n" +
            "                       Log.d(TAG, \"onError: \");\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onComplete() {\n" +
            "                       Log.d(TAG, \"onComplete: \");\n" +
            "                   }\n" +
            "               });\n" +
            "\n" +
            " Observable.error(new RuntimeException())\n" +
            "               .subscribe(new Observer<Object>() {\n" +
            "                   @Override\n" +
            "                   public void onSubscribe(Disposable d) {\n" +
            "                       Log.d(TAG, \"onSubscribe: \"+d);\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onNext(Object o) {\n" +
            "                       Log.d(TAG, \"onNext: \"+o);\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onError(Throwable e) {\n" +
            "                       Log.d(TAG, \"onError: \");\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onComplete() {\n" +
            "                       Log.d(TAG, \"onComplete: \");\n" +
            "                   }\n" +
            "               });\n" +
            "Observable.never()\n" +
            "               .subscribe(new Observer<Object>() {\n" +
            "                   @Override\n" +
            "                   public void onSubscribe(Disposable d) {\n" +
            "                       Log.d(TAG, \"onSubscribe: \"+d);\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onNext(Object o) {\n" +
            "                       Log.d(TAG, \"onNext: \"+o);\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onError(Throwable e) {\n" +
            "                       Log.d(TAG, \"onError: \");\n" +
            "                   }\n" +
            "\n" +
            "                   @Override\n" +
            "                   public void onComplete() {\n" +
            "                       Log.d(TAG, \"onComplete: \");\n" +
            "                   }\n" +
            "               });\n";

    public static final String RXJAVA_WAITCREATE = "三. 延迟创建\n" +
            "需求场景：\n" +
            "\n" +
            "定时操作：在经过了x秒后，需要自动执行y操作\n" +
            "周期性操作：每隔x秒后，需要自动执行y操作\n" +
            "1.defer（）\n" +
            "作用:defer（）操作符会一直等待直到有观察者订阅它，然后它使用Observable工厂方法生成一个Observable。在某些情况下，等待直到最后一分钟（就是知道订阅发生时）才生成Observable可以确保Observable包含最新的数据。\n" +
            "使用场景：动态创建被观察者对象（Observable） & 获取最新的Observable对象数据\n" +
            "\n" +
            "\n" +
            "  //  1. 第1次对i赋值\n" +
            "         i= 10;\n" +
            "\n" +
            "        Observable<Integer> observable = Observable.defer(new Callable<ObservableSource<? extends Integer>>() {\n" +
            "            @Override\n" +
            "            public ObservableSource<? extends Integer> call() throws Exception {\n" +
            "                return Observable.just(i);\n" +
            "            }\n" +
            "        });\n" +
            "\n" +
            "        //  1. 第1次对i赋值\n" +
            "        i = 15;\n" +
            "        observable\n" +
            "                .subscribe(new Observer<Object>() {\n" +
            "                    @Override\n" +
            "                    public void onSubscribe(Disposable d) {\n" +
            "                        Log.d(TAG, \"onSubscribe: \" + d);\n" +
            "                    }\n" +
            "\n" +
            "                    @Override\n" +
            "                    public void onNext(Object o) {\n" +
            "                        Log.d(TAG, \"onNext: \" + o);\n" +
            "                    }\n" +
            "\n" +
            "                    @Override\n" +
            "                    public void onError(Throwable e) {\n" +
            "                        Log.d(TAG, \"onError: \");\n" +
            "                    }\n" +
            "\n" +
            "                    @Override\n" +
            "                    public void onComplete() {\n" +
            "                        Log.d(TAG, \"onComplete: \");\n" +
            "                    }\n" +
            "                });\n" +
            "\n" +
            "\n" +
            "2.timer（）\n" +
            "作用:创建一个Observable，它在一个给定的延迟后发射一个特殊的值。\n" +
            "应用:延迟指定事件，发送一个0，一般用于检测\n" +
            "\n" +
            "        // 该例子 = 延迟2s后，发送一个long类型数值\n" +
            "        Observable.timer(2, TimeUnit.SECONDS).subscribe(new Observer<Long>() {\n" +
            "            @Override\n" +
            "            public void onSubscribe(Disposable d) {\n" +
            "                Log.d(TAG, \"开始采用subscribe连接\");\n" +
            "            }\n" +
            "\n" +
            "            @Override\n" +
            "            public void onNext(Long value) {\n" +
            "                Log.d(TAG, \"接收到了事件\" + value);\n" +
            "            }\n" +
            "\n" +
            "            @Override\n" +
            "            public void onError(Throwable e) {\n" +
            "                Log.d(TAG, \"对Error事件作出响应\");\n" +
            "            }\n" +
            "\n" +
            "            @Override\n" +
            "            public void onComplete() {\n" +
            "                Log.d(TAG, \"对Complete事件作出响应\");\n" +
            "            }\n" +
            "        });\n" +
            "\n" +
            "\n" +
            "3.interval（）\n" +
            "作用 : 按固定的时间间隔发射一个无限递增的整数序列。\n" +
            "interval(long,TimeUnit,Scheduler))\n" +
            "参数说明： 参数1 = 第1次延迟时间，参数2 = 间隔时间数字，参数3 = 时间单位；\n" +
            "\n" +
            "    Observable.interval(3, 1, TimeUnit.SECONDS)\n" +
            "                // 该例子发送的事件序列特点：延迟3s后发送事件，每隔1秒产生1个数字（从0开始递增1，无限个）\n" +
            "                .subscribe(new Observer<Long>() {\n" +
            "                    @Override\n" +
            "                    public void onSubscribe(Disposable d) {\n" +
            "                        Log.d(TAG, \"开始采用subscribe连接\");\n" +
            "                    }\n" +
            "\n" +
            "                    @Override\n" +
            "                    public void onNext(Long value) {\n" +
            "                        Log.d(TAG, \"接收到了事件\" + value);\n" +
            "                    }\n" +
            "\n" +
            "                    @Override\n" +
            "                    public void onError(Throwable e) {\n" +
            "                        Log.d(TAG, \"对Error事件作出响应\");\n" +
            "                    }\n" +
            "\n" +
            "                    @Override\n" +
            "                    public void onComplete() {\n" +
            "                        Log.d(TAG, \"对Complete事件作出响应\");\n" +
            "                    }\n" +
            "                });\n" +
            "\n" +
            "\n" +
            "4.intervalRange（）\n" +
            "作用:发送事件的特点：每隔指定时间 就发送 事件，可指定发送的数据（从0开始、无限递增1的的整数）的数量\n" +
            "\t// 参数1 = 事件序列起始点；\n" +
            "        // 参数2 = 事件数量；\n" +
            "        // 参数3 = 第1次事件延迟发送时间；\n" +
            "        // 参数4 = 间隔时间数字；\n" +
            "        // 参数5 = 时间单位\n" +
            "Observable.intervalRange(3, 10, 2, 1, TimeUnit.SECONDS)\n" +
            "                // 该例子发送的事件序列特点： \n" +
            "                // 1. 从3开始，一共发送10个事件； \n" +
            "                // 2. 第1次延迟2s发送，之后每隔2秒产生1个数字（从0开始递增1，无限个） \n" +
            "                .subscribe(new Observer<Long>() {\n" +
            "                    @Override\n" +
            "                    public void onSubscribe(Disposable d) {\n" +
            "                        Log.d(TAG, \"开始采用subscribe连接\");\n" +
            "                    } // 默认最先调用复写的 onSubscribe（） \n" +
            "\n" +
            "                    @Override\n" +
            "                    public void onNext(Long value) {\n" +
            "                        Log.d(TAG, \"接收到了事件\" + value);\n" +
            "                    }\n" +
            "\n" +
            "                    @Override\n" +
            "                    public void onError(Throwable e) {\n" +
            "                        Log.d(TAG, \"对Error事件作出响应\");\n" +
            "                    }\n" +
            "\n" +
            "                    @Override\n" +
            "                    public void onComplete() {\n" +
            "                        Log.d(TAG, \"对Complete事件作出响应\");\n" +
            "                    }\n" +
            "                });\n" +
            "\n" +
            "\n" +
            "\n" +
            "5.range（） /rangeLong（）\n" +
            "range（） 作用：连续发送 1个事件序列，可指定范围,作用类似于intervalRange（），但区别在于：无延迟发送事件\n" +
            "\n" +
            "rangeLong（）类似于range（），区别在于该方法支持数据类型 = Long\n" +
            "\n" +
            "\n" +
            " // 参数说明：\n" +
            "        // 参数1 = 事件序列起始点；\n" +
            "        // 参数2 = 事件数量；\n" +
            "        // 注：若设置为负数，则会抛出异常\n" +
            "        Observable.range(3,10)\n" +
            "                // 该例子发送的事件序列特点：从3开始发送，每次发送事件递增1，一共发送10个事件\n" +
            "                .subscribe(new Observer<Integer>() {\n" +
            "                    @Override\n" +
            "                    public void onSubscribe(Disposable d) {\n" +
            "                        Log.d(TAG, \"开始采用subscribe连接\");\n" +
            "                    } // 默认最先调用复写的 onSubscribe（）\n" +
            "\n" +
            "                    @Override\n" +
            "                    public void onNext(Integer value) {\n" +
            "                        Log.d(TAG, \"接收到了事件\" + value);\n" +
            "                    }\n" +
            "\n" +
            "                    @Override\n" +
            "                    public void onError(Throwable e) {\n" +
            "                        Log.d(TAG, \"对Error事件作出响应\");\n" +
            "                    }\n" +
            "\n" +
            "                    @Override\n" +
            "                    public void onComplete() {\n" +
            "                        Log.d(TAG, \"对Complete事件作出响应\");\n" +
            "                    }\n" +
            "                });\n" +
            "\n" +
            "\n";
}
